package com.example.dell.network.http;


import java.io.File;
import java.util.List;

import okhttp3.FormBody;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;

/**
 * 请求体业务类：
 */
public class RequestBodyUtils {


    /**
     * @return
     */
    //  登录
    public static RequestBody getLoginRequestBody(String phone, String password) {
        RequestBody body = new FormBody.Builder()
                .add("phone", phone)
                .add("password", password)
                .build();
        return body;
    }

    //  微信登录
    public static RequestBody getWxLoginRequestBody(String openid) {
        RequestBody body = new FormBody.Builder()
                .add("openId", openid)
                .build();
        return body;
    }

    //  微信登录
    public static RequestBody gotoGetGift(String openid) {
        RequestBody body = new FormBody.Builder()
                .add("actId", openid)
                .build();
        return body;
    }

    //获取验证码  找回密码和更改账号传1
    public static RequestBody getRegistBody(String phone, String flag) {
        RequestBody body = new FormBody.Builder()
                .add("phone", phone)
                .add("flag", flag)
                .build();
        return body;
    }

    //获取验证码
    public static RequestBody getRegistBody(String phone) {
        RequestBody body = new FormBody.Builder()
                .add("phone", phone)
                .build();
        return body;
    }

    //活动
    public static RequestBody getGift(String productId) {
        return new FormBody.Builder()
                .add("productId", productId)
                .build();
    }

    //用户注册
    public static RequestBody registerUser(String phone, String checkCode, String password) {
        return new FormBody.Builder()
                .add("phone", phone)
                .add("checkCode", checkCode)
                .add("password", password)
                .build();
    }

    //用户注册,从活动进来的
    public static RequestBody registerUserAct(String phone, String checkCode, String password, String id, String invitecode) {
        return new FormBody.Builder()
                .add("phone", phone)
                .add("checkCode", checkCode)
                .add("password", password)
                .add("actId", id)
                .add("productId", "1")
                .add("invitecode", invitecode)
                .build();
    }

    //用户微信注册
    public static RequestBody registerUserWx(String phone, String checkCode, String password, String name, String openId, String iconUrl) {
        return new FormBody.Builder()
                .add("phone", phone)
                .add("checkCode", checkCode)
                .add("password", password)
                .add("nickName", name)
                .add("openId", openId)
                .add("icon", iconUrl)
                .build();
    }

    //用户微信绑定
    public static RequestBody bindWx(String phone, String checkCode, String name, String openId, String iconUrl) {
        return new FormBody.Builder()
                .add("phone", phone)
                .add("nickName", name)
                .add("openId", openId)
                .add("icon", iconUrl)
                .add("validateCode", checkCode)
                .build();
    }

    //更改昵称
    public static RequestBody getChangeNickNameBody(String nickName) {
        return new FormBody.Builder()
                .add("nickname", nickName)
                .build();
    }

    //用户注册有邀请码
    public static RequestBody registerUser(String phone, String checkCode, String password, String invitecode) {
        RequestBody body = new FormBody.Builder()
                .add("phone", phone)
                .add("checkCode", checkCode)
                .add("password", password)
                .add("invitecode", invitecode)
                .add("productId", "1")
                .build();
        return body;
    }

    //根据手机号检查用户是否已注册
    public static RequestBody checkUserByPhone(String phone) {
        RequestBody body = new FormBody.Builder()
                .add("phone", phone)
                .build();
        return body;
    }

    //判断邀请码输入是否正确
    public static RequestBody checkInvitecode(String phone) {
        RequestBody body = new FormBody.Builder()
                .add("invitecode", phone)
                .build();
        return body;
    }

    //找回密码
    public static RequestBody findPwd(String phone, String checkCode, String password, String rePassword) {
        RequestBody body = new FormBody.Builder()
                .add("phone", phone)
                .add("checkCode", checkCode)
                .add("password", password)
                .add("rePassword", rePassword)
                .build();
        return body;
    }

    //秘籍页
    public static RequestBody index() {
        RequestBody body = new FormBody.Builder()
                .add("pageNum", 4 + "")
                .build();
        return body;
    }

    //搜索
    public static RequestBody search(String string) {
        RequestBody body = new FormBody.Builder()
                .add("keyword", string)

                .build();
        return body;
    }

    //基础数据
    public static RequestBody search(String string, int type, int size) {
        RequestBody body = new FormBody.Builder()
                .add("keyword", string)
                .add("type", type + "")
                .add("pageSize", size + "")
                .build();
        return body;
    }

    //基础数据
    public static RequestBody basicdata() {
        return new FormBody.Builder()
                .build();
    }

    //相关课程
    public static RequestBody xiangguan(int courseId) {
        RequestBody body = new FormBody.Builder()
                .add("id", String.valueOf(courseId))
                .build();
        return body;
    }

    //列表更多
    public static RequestBody more(int i) {
        RequestBody body = new FormBody.Builder()
                .add("pageSize", i + "")
                .build();
        return body;
    }
    public static RequestBody moreCollage(int i) {
        RequestBody body = new FormBody.Builder()
                .add("pageSize", i + "")
                .build();
        return body;
    }

    // 高分资料的列表
    public static RequestBody more(int i, int sbt, int subject) {
        RequestBody body = new FormBody.Builder()
                .add("pageSize", i + "")
                .add("sbt", sbt + "")
                .add("subject", subject + "")
                .build();
        return body;
    }

    // 最新公告的列表
    public static RequestBody noticemore(int i, int area, int sbt) {
        RequestBody body = new FormBody.Builder()
                .add("pageSize", i + "")
                .add("area", area + "")
                .add("sbt", sbt + "")
                .build();
        return body;
    }

    //详情
    public static RequestBody getSingle(int i) {
        RequestBody body = new FormBody.Builder()
                .add("id", i + "")
                .build();
        return body;
    }

    //收藏
    public static RequestBody favorite(int type, int entityId) {
        RequestBody body = new FormBody.Builder()
                .add("type", type + "")
                .add("entityId", entityId + "")
                .build();
        return body;
    }

    //取消收藏
    public static RequestBody unFavorite(int type, int entityId) {
        RequestBody body = new FormBody.Builder()
                .add("type", type + "")
                .add("entityId", entityId + "")
                .build();
        return body;
    }

    //评论查询
    public static RequestBody selectAllComments(int size, int type, int uuid) {
        RequestBody body = new FormBody.Builder()
                .add("pageSize", size + "")
                .add("type", type + "")
                .add("uuid", uuid + "")
                .build();
        return body;
    }

    //添加评论
    public static RequestBody addComments(int id, String content, int entryid) {
        RequestBody body = new FormBody.Builder()
                .add("type", id + "")
                .add("content", content)
                .add("uuid", entryid + "")
                .build();
        return body;
    }

    public static RequestBody addCommentStar(int id, String content, int entryid, int star) {
        RequestBody body = new FormBody.Builder()
                .add("type", id + "")
                .add("content", content)
                .add("uuid", entryid + "")
                .add("star", star + "")
                .build();
        return body;
    }

    //点赞
    public static RequestBody like(String uuid, int type, int entityId) {

        RequestBody body = new FormBody.Builder()
                .add("uuid", uuid)
                .add("type", type + "")
                .add("entityId", entityId + "")
                .build();
        return body;
    }

    //听课列表
    public static RequestBody course(int siz, int sbt, String subject, int priceRange) {
        RequestBody body = new FormBody.Builder()
                .add("pageSize", siz + "")
                .add("sbt", sbt + "")
                .add("subject", subject)
                .add("priceRange", priceRange + "")
                .build();
        return body;
    }

    //MultipartFile
    public static RequestBody uploadImage(String url) {
        RequestBody requestBody = new MultipartBody.Builder()
                .setType(MultipartBody.FORM)
                .addFormDataPart("profile", "lwgk.jpg", RequestBody.create(MediaType.parse("image/png"), new File(url)))
                .build();
        return requestBody;
    }

    //校验验证码是    更新账号
    public static RequestBody checkCode(String ph, String code) {
        RequestBody body = new FormBody.Builder()
                .add("phone", ph)
                .add("checkCode", code)
                .build();
        return body;
    }

    //修改密码
    public static RequestBody updatapassword(String ph, String code, String ps) {
        RequestBody body = new FormBody.Builder()
                .add("password", ph)
                .add("pwd", code)
                .add("rePwd", ps)
                .build();
        return body;
    }

    //新增收货地址
    public static RequestBody newAddAddress(String name, String phone, String pro, String city, String area, String address) {
        RequestBody body = new FormBody.Builder()
                .add("nickName", name)
                .add("phone", phone)
                .add("province", pro)
                .add("city", city)
                .add("area", area)
                .add("address", address)
                .build();
        return body;
    }

    // 编辑收货地址
    public static RequestBody newAddAddress(String name, String phone, String pro, String city, String area, String address, int id) {
        RequestBody body = new FormBody.Builder()
                .add("nickName", name)
                .add("phone", phone)
                .add("province", pro)
                .add("city", city)
                .add("area", area)
                .add("address", address)
                .add("id", id + "")
                .build();
        return body;
    }

    //删除收货地址 和设置默认的
    public static RequestBody delAddress(int ph) {
        RequestBody body = new FormBody.Builder()
                .add("id", ph + "")
                .build();
        return body;
    }

    // 意见反馈
    public static RequestBody feedBack(String ph, String phone, List<String> url) {

        MultipartBody.Builder multipartBodyBuilder = new MultipartBody.Builder();
        multipartBodyBuilder.setType(MultipartBody.FORM);

        multipartBodyBuilder.addFormDataPart("feedback", ph);
        multipartBodyBuilder.addFormDataPart("phone", phone);

        //遍历paths中所有图片绝对路径到builder，并约定key如“upload”作为后台接受多张图片的key
        if (url != null) {
            for (int i = 0; i < url.size(); i++) {
                multipartBodyBuilder.addFormDataPart("backfiles", "Lwgk" + System.currentTimeMillis() + ".jpg", RequestBody.create(MediaType.parse("image/png"), new File(url.get(i))));
            }
        }
        RequestBody requestBody = multipartBodyBuilder.build();
        return requestBody;
    }
    // 行测意见反馈
    public static RequestBody XCfeedBack(String ph, String questionId, List<String> url) {

        MultipartBody.Builder multipartBodyBuilder = new MultipartBody.Builder();
        multipartBodyBuilder.setType(MultipartBody.FORM);

        multipartBodyBuilder.addFormDataPart("feedback", ph);
        multipartBodyBuilder.addFormDataPart("questionId", questionId);


        //遍历paths中所有图片绝对路径到builder，并约定key如“upload”作为后台接受多张图片的key
        if (url != null) {
            for (int i = 0; i < url.size(); i++) {
                multipartBodyBuilder.addFormDataPart("backfiles", "Lwgk" + System.currentTimeMillis() + ".jpg", RequestBody.create(MediaType.parse("image/png"), new File(url.get(i))));
            }
        }
        RequestBody requestBody = multipartBodyBuilder.build();
        return requestBody;
    }
    //开团接口
    public static RequestBody collage(String id, String type, String externalno ){
        FormBody body = new FormBody.Builder()
                .add("courseId", id)
                .add("type", type)
                .add("externalno", externalno)
                .build();
        return body;
    }
    // 立即购买的接口
    public static RequestBody buyNow(String id) {
        RequestBody body = new FormBody.Builder()
                .add("courseId", id)
                .build();
        return body;
    }

    // 立即购买的接口
    public static RequestBody addMyCourse(String id) {
        RequestBody body = new FormBody.Builder()
                .add("id", id)
                .build();
        return body;
    }


    // 立即购买的接口
    public static RequestBody addOrder(int externalno, String addressNo, String userVoucherId, String userName, int sex, int isSingle, int isdeposit, int payType, int type) {
        RequestBody body = new FormBody.Builder()
                .add("externalno", externalno + "")
                .add("addressNo", addressNo)
                .add("userVoucherId", userVoucherId + "")
                .add("username", userName)
                .add("sex", sex + "")
                .add("isSingle", isSingle + "")
                .add("isdeposit", isdeposit + "")
                .add("payType", payType + "")
                .add("type", String.valueOf(type))
                .build();
        return body;
    }

    // 支付宝支付接口
    public static RequestBody aliPay(String id) {
        RequestBody body = new FormBody.Builder()
                .add("orderNumber", id)
                .build();
        return body;
    }

    public static RequestBody getdetailes(String i) {
        RequestBody body = new FormBody.Builder()
                .add("id", i + "")
                .build();
        return body;
    }

    /**
     * 我的课程列表
     *
     * @param i
     * @return
     */
    public static RequestBody getMyCourse(int i, int type) {
        RequestBody body = new FormBody.Builder()
                .add("pageSize", i + "")
//                .add("cType", type + "")
                .build();
        return body;
    }


    /**
     * 新增学习计划
     */
    public static RequestBody addPlan(String name, String tipTime, String rate, String dnames) {
        RequestBody body = new FormBody.Builder()
                .add("name", name)
                .add("tipTime", tipTime)
                .add("rate", rate)
                .add("dnames", dnames)
                .build();
        return body;
    }

    /**
     * 修改学习计划
     */
    public static RequestBody aliderPlan(int i, String name, String tipTime, String rate, String dids, String dnames) {
        RequestBody body = new FormBody.Builder()
                .add("id", i + "")
                .add("name", name)
                .add("tipTime", tipTime)
                .add("rate", rate)
                .add("dids", dids)
                .add("dnames", dnames)
                .build();
        return body;
    }

    /**
     * 关闭或者打开学习提醒
     */

    public static RequestBody isOpen(int i, int type) {
        RequestBody body = new FormBody.Builder()
                .add("id", i + "")
                .add("flag", type + "")
                .build();
        return body;
    }

    public static RequestBody complete(int i, String type) {
        RequestBody body = new FormBody.Builder()
                .add("id", i + "")
                .add("status", type + "")
                .build();
        return body;
    }

    /**
     *
     * @param num 某一页
     * @param size 一页多少条数据
     * @return
     */
    public static RequestBody refreshProblem(int num, int size) {
        RequestBody body = new FormBody.Builder()
                .add("pageIndex", num + "")
                .add("pageSize", size + "")
                .build();
        return body;
    }

    /**
     *
     * @param page 页数
     * @param pageSize 多少条
     * @param isAll 1代表全部，0代表部分
     * @return
     */
    public static RequestBody mallList(int page, int pageSize, String isAll) {
        RequestBody body = new FormBody.Builder()
                .add("pageIndex", page + "")
                .add("pageSize", pageSize + "")
                .add("all", isAll + "")
                .build();
        return body;
    }

    public static RequestBody goodsExchange(String goodid, String addressNo){
        RequestBody body = new FormBody.Builder()
                .add("goodsId", goodid + "")
                .add("addressNo", addressNo + "")
                .build();
        return body;

    }

    public static RequestBody goodGetExchange(String goodid, String addressNo){
        RequestBody body = new FormBody.Builder()
                .add("id", goodid + "")
                .add("addressNo", addressNo + "")
                .build();
        return body;

    }

    /**
     * 提交未选择职位
     */
    public static RequestBody getPostionId(String mockId) {
        RequestBody body = new FormBody.Builder()
                .add("mockId", mockId + "")
                .add("posId", 0 + "")
                .add("areaId", 0 + "")
                .build();
        return body;
    }

    /**
     * 职位选择获取地区职位列表
     */
    public static RequestBody addMockId(String id) {
        RequestBody body = new FormBody.Builder()
                .add("mockId", id)
                .build();
        return body;
    }
    /**
     * 职位选择获取地区以外更多的职位列表
     */
    public static RequestBody addMockList(String mockId, String areaId) {
        RequestBody body = new FormBody.Builder()
                .add("mockId", mockId)
                .add("areaId", areaId)
                .build();
        return body;
    }
    /**
     * 提交职位的id
     */
    public static RequestBody selectSubmitPostion(String mockId, String areaId, String posId, String gkId) {
        RequestBody body = new FormBody.Builder()
                .add("mockId", mockId)
                .add("areaId", areaId)
                .add("posId", posId)
                .add("gk", gkId)
                .build();
        return body;
    }
}